//
//  VTableViewCell.m
//  QuickReadComic
//
//  Created by 苗钧豪 on 16/9/2.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "VTableViewCell.h"
#import "VCollectionViewCell.h"
#import <AVFoundation/AVFoundation.h>
#import "VCollectionViewCell.h"
#import "JHFlowLayout.h"
#import "UIImageView+WebCache.h"
#import "VCommunityViewController.h"
@implementation VTableViewCell
- (void)awakeFromNib {
    [super awakeFromNib];
    self.array = [NSMutableArray array];
    self.lastArr = [NSMutableArray array];
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setup];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}
- (void)setup {
    [self.lastArr removeAllObjects];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _lastArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    VCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VColl" forIndexPath:indexPath];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:_lastArr[indexPath.row]]];
    
    return cell;
}
- (void)top:(UITapGestureRecognizer *)top {
    self.imgview = (UIImageView *)top.view;
    NSLog(@"%@",_imgview.image);
    self.blackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
    _blackView.backgroundColor = [UIColor blackColor];
    _blackView.contentMode = UIViewContentModeScaleAspectFill;
    _blackView.image = self.imgview.image;
    _blackView.userInteractionEnabled = YES;
    self.tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [_blackView addGestureRecognizer:_tap];
}
- (void)tap:(UITapGestureRecognizer *)tap {
    
        [self.blackView removeFromSuperview];
    
}
- (void)assignment {
    _layout = [[UICollectionViewFlowLayout alloc]init];
    _layout.itemSize = CGSizeMake(100, 100);
    _layout.minimumLineSpacing = 5;
    _layout.minimumInteritemSpacing = 5;
    [_imageCollectionView setCollectionViewLayout:_layout];
    _imageCollectionView.delegate = self;
    _imageCollectionView.dataSource = self;
    [_imageCollectionView registerNib:[UINib nibWithNibName:@"VCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"VColl"];
    for (NSString *string in _feeds.content.images) {
        [self.array addObject:string];
    }
    _string = _feeds.content.image_base;
    for (int i = 0; i < self.array.count; i ++) {
        NSString *newStr = [_string stringByAppendingString:self.array[i]];
        [self.lastArr addObject:newStr];
    }
    if (_lastArr.count == 0) {
//        _imageCollectionView.frame = CGRectMake(0, 0, 0, 0);
        _ZeroHeight.priority = 999;
        _MoRenHeight.priority = 99;
        _OneHeight.priority = 99;
        _TwoHeight.priority = 99;
        _ThreeHeight.priority = 99;
    } else if (_lastArr.count <= 3 && _lastArr.count > 0) {
//        _imageCollectionView.frame = CGRectMake(0, 0, 100 * _lastArr.count, 100);
        _ZeroHeight.priority = 99;
        _MoRenHeight.priority = 99;
        _OneHeight.priority = 999;
        _TwoHeight.priority = 99;
        _ThreeHeight.priority = 99;
    } else if (_lastArr.count > 3 && _lastArr.count <= 6) {
        if (_lastArr.count == 4) {
//            _imageCollectionView.frame = CGRectMake(0, 0, 205, 205);
            _ZeroHeight.priority = 99;
            _MoRenHeight.priority = 99;
            _OneHeight.priority = 99;
            _TwoHeight.priority = 999;
            _ThreeHeight.priority = 99;
        } else {
//            _imageCollectionView.frame = CGRectMake(0, 0, 310, 205);
            _ZeroHeight.priority = 99;
            _MoRenHeight.priority = 99;
            _OneHeight.priority = 99;
            _TwoHeight.priority = 999;
            _ThreeHeight.priority = 99;
        }
    } else if (_lastArr.count > 6 && _lastArr.count <= 9) {
//        _imageCollectionView.frame = CGRectMake(0, 0, 310, 310);
        _ZeroHeight.priority = 99;
        _MoRenHeight.priority = 99;
        _OneHeight.priority = 99;
        _TwoHeight.priority = 99;
        _ThreeHeight.priority = 999;
    }
    [_imageCollectionView reloadData];
}


@end
